package edu.cth.stud.accelerateit.view;

import edu.cth.stud.accelerateit.core.WordFinderModel;

/**
 * A class meant to act as the middle-ground between platform-specific GUIs and
 * the more platform-independent application model. GUI classes may call on this
 * class to communicate with the model.
 * 
 * Uses the singleton pattern.
 * 
 * @author Marten
 * 
 */
public class GUIController implements IGUIController {

	private static GUIController controller;

	private GUIController() {
		controller = this;
	}

	@Override
	public void registerListener(IGUIComponent listener) {
		// Throw it down the line!
		WordFinderModel.getInstance().registerListener(listener);

	}

	public void unregisterListener(IGUIComponent listener) {
		// Throw it down the line!
		WordFinderModel.getInstance().unregisterListener(listener);
	}

	public static GUIController getInstance() {
		if (controller == null) {
			controller = new GUIController();
		}
		return controller;
	}

	@Override
	public void enterWordDefinitionSearch(String searchTerm) {
		// Throw it down the line!
		WordFinderModel.getInstance().performWordDefinitionSearch(searchTerm);
	}

	@Override
	public void enterDictionarySearch(String availableLetters, String gameboardState) {
		// Throw it down the line!
		WordFinderModel.getInstance().performDictionarySearch(availableLetters, gameboardState);
	}

	/**
	 * This method is used to ensure that all activities are finished correctly,
	 * and none are lingering behind when the application closes.
	 */
	@Override
	public void terminateApplication() {
		WordFinderModel.getInstance().terminateApplication();
	}

}
